home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / BC++ Builder / DATA.Z / DLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-10  |  21.4 KB  |  697 lines

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1997 Borland International Inc.  All Rights Reserved.
  4. //---------------------------------------------------------------------------
  5. /* DLG.CPP: Dialogbox Expert implementation (DlgExpert class)
  6. */
  7.  
  8. //---------------------------------------------------------------
  9. #include <vcl\vcl.h>
  10. #pragma hdrstop
  11.  
  12. #include <vcl\Proxies.hpp>
  13. #include <vcl\controls.hpp>
  14. #include <vcl\classes.hpp>
  15. #include <vcl\VirtIntf.hpp>
  16. #include <vcl\IStreams.hpp>
  17.  
  18. #include <memory>         // auto_ptr (no .H on this!)
  19. using namespace std;
  20.  
  21. #include "dlg.h"          // dialogbox expert class defintion
  22.  
  23. //---------------------------------------------------------------
  24. #pragma resource "*.dfm"
  25. TDlgExpert *DlgExpert;
  26.  
  27. const int
  28.   // page numbers
  29.   pgStyle          = 0,    // multi vs. single page dialog
  30.   pgPages          = 1,    // page names
  31.   pgButtons        = 2,    // button layouts
  32.   SourceBufferSize = 8096;
  33.  
  34. int DlgHeight = 250;
  35. int DlgWidth  = 400;
  36. int BtnHeight =  25;
  37. int BtnWidth  =  75;
  38.  
  39. //========================================[ TDlgExpert ]=========
  40. __fastcall TDlgExpert::TDlgExpert(TComponent* AOwner)
  41.                       :TForm(AOwner)
  42. {
  43. }
  44.  
  45. //========================================[ TDlgExpert ]=========
  46. __fastcall TDlgExpert::TDlgExpert(HWND ParentWindow)
  47.                       :TForm(ParentWindow)
  48. {
  49. }
  50.  
  51. //========================================[ TDlgExpert ]=========
  52. __fastcall TDlgExpert::TDlgExpert(TComponent* AOwner, int Dummy)
  53.                       :TForm(AOwner, Dummy)
  54. {
  55. }
  56.  
  57. //========================================[ TDlgExpert ]=========
  58. __fastcall TDlgExpert::~TDlgExpert(void) {
  59. }
  60.  
  61. //========================================= TDlgExpert ==========
  62. void __fastcall TDlgExpert::FormCreate(TObject *Sender)
  63. {
  64.   DrawBitmap = new Graphics::TBitmap;
  65.   PrevClick(this);
  66.   RefreshButtons();
  67. } // end of TDlgExpert.FormCreate()
  68.  
  69. //========================================= TDlgExpert ==========
  70. void __fastcall TDlgExpert::FormDestroy(TObject *Sender)
  71. {
  72.   delete DrawBitmap;
  73. } // end of TDlgExpert.FormDestroy()
  74.  
  75. //========================================= TDlgExpert ==========
  76. void __fastcall TDlgExpert::CancelClick(TObject *Sender)
  77. {
  78.   Close();
  79. } // end of TDlgExpert.CancelClick()
  80.  
  81. //========================================= TDlgExpert ==========
  82. // Paint the sample pane based on the currently selected options
  83. void __fastcall TDlgExpert::SamplePaint(TObject *Sender)
  84. {
  85.   int X;
  86.   int Y;
  87.  
  88.   // always paint the background dialog
  89.   DrawBitmap = new Graphics::TBitmap;
  90.   DrawBitmap->Handle = LoadBitmap(instance, "DIALOG");
  91.   Sample->Canvas->Draw(0, 0, DrawBitmap);
  92.  
  93.   if (Definition.Contains(daMultPg))
  94.   {
  95.     DrawBitmap->Handle = LoadBitmap(instance, "MULTPG");
  96.     Sample->Canvas->Draw(4, 16, DrawBitmap);
  97.   }
  98.  
  99.   if (Definition.Contains(daBtnsV))
  100.   {
  101.     DrawBitmap->Handle = LoadBitmap(instance, "BTNSV");
  102.     X = 75;
  103.     Y = 22;
  104.  
  105.     if (Definition.Contains(daMultPg))
  106.     {
  107.       X -= 2;
  108.       Y += 4;
  109.     }
  110.  
  111.     Sample->Canvas->Draw(X, Y, DrawBitmap);
  112.   }
  113.  
  114.   if (Definition.Contains(daBtnsH))
  115.   {
  116.     DrawBitmap->Handle = LoadBitmap(instance, "BTNSH");
  117.     X = 50;
  118.     Y = 55;
  119.  
  120.     if (Definition.Contains(daMultPg))
  121.       Y -= 4;
  122.  
  123.     Sample->Canvas->Draw(X, Y, DrawBitmap);
  124.   }
  125.  
  126.   delete DrawBitmap;
  127.   DrawBitmap = 0;
  128. } // end of TDlgExpert::SamplePaint()
  129.  
  130. //========================================= TDlgExpert ==========
  131. void __fastcall TDlgExpert::StyleClick(TObject *Sender)
  132. {
  133.   if (rbMultPg->Checked)
  134.     Definition << daMultPg;
  135.   else
  136.     Definition >> daMultPg;
  137.  
  138.   SamplePaint(this);
  139. } // end of TDlgExpert.StyleClick(
  140.  
  141. //========================================= TDlgExpert ==========
  142. void __fastcall TDlgExpert::BtnClick(TObject *Sender)
  143. {
  144.   if (rbBtnsV->Checked)
  145.     Definition << daBtnsV;
  146.   else
  147.     Definition >> daBtnsV;
  148.  
  149.   if (rbBtnsH->Checked)
  150.     Definition << daBtnsH;
  151.   else
  152.     Definition >> daBtnsH;
  153.  
  154.   SamplePaint(this);
  155. } // end of TDlgExpert.BtnClick()
  156.  
  157. //========================================= TDlgExpert ==========
  158. void __fastcall TDlgExpert::PrevClick(TObject *Sender)
  159. {
  160.   switch(PageControl->ActivePage->PageIndex)
  161.   {
  162.     case pgStyle:
  163.       return;
  164.     case pgPages:
  165.       PageControl->ActivePage = PageControl->Pages[pgStyle];
  166.       break;
  167.     case pgButtons:
  168.       if (Definition.Contains(daMultPg))
  169.         PageControl->ActivePage = PageControl->Pages[pgPages];
  170.       else
  171.         PageControl->ActivePage = PageControl->Pages[pgStyle];
  172.       break;
  173.   }
  174.  
  175.   RefreshButtons();
  176. } // end of TDlgExpert::PrevClick()
  177.  
  178. //========================================= TDlgExpert ==========
  179. void __fastcall TDlgExpert::NextClick(TObject *Sender)
  180. {
  181.   switch(PageControl->ActivePage->PageIndex)
  182.   {
  183.     case pgStyle:
  184.       if (Definition.Contains(daMultPg))
  185.         PageControl->ActivePage = PageControl->Pages[pgPages];
  186.       else
  187.         PageControl->ActivePage = PageControl->Pages[pgButtons];
  188.       break;
  189.     case pgPages:
  190.       PageControl->ActivePage = PageControl->Pages[pgButtons];
  191.       break;
  192.     case pgButtons:
  193.       ModalResult = mrOK;
  194.       return;
  195.   }
  196.  
  197.   RefreshButtons();
  198. } // end of TDlgExpert::NextClick()
  199.  
  200. //========================================= TDlgExpert ==========
  201. void __fastcall TDlgExpert::RefreshButtons(void)
  202. {
  203.   PrevButton->Enabled = PageControl->ActivePage->PageIndex > 0;
  204.   if (PageControl->ActivePage->PageIndex == pgButtons)
  205.     NextButton->Caption = LoadStr(sFinish);
  206.   else
  207.     NextButton->Caption = LoadStr(sNext);
  208. } // end of TDlgExpert::RefreshButtons()
  209.  
  210. //========================================= TDlgExpert ==========
  211. // Create the dialog defined by the user
  212. TForm* __fastcall TDlgExpert::DoFormCreation(const String ffn)
  213. {
  214.   TPoint       BtnPos;
  215.   TPageControl *PgCtrl;
  216.   TForm        *Result;
  217.  
  218.   // Create form symbol based on button orientation and...
  219.   if (!Definition.Contains(daBtnsV) && !Definition.Contains(daBtnsH))
  220.     FormName = "OKNoButDlg";
  221.   else {
  222.     if (Definition.Contains(daBtnsH))
  223.       FormName = "OKBottomDlg";
  224.     else
  225.       FormName = "OKRightDlg";
  226.   }
  227.  
  228.   // ...number associated with the forms's module (file) name.
  229.   FormName += ffn.c_str()[ffn.Length()-1];
  230.  
  231.   // Create the dialog's form and...
  232.   Result = new TForm(this);
  233.  
  234.   // ...a proxy form for it.
  235.   Proxies::CreateSubClass(Result, "T" + FormName, __classid(TForm));
  236.  
  237.   // Give the form its personality and...
  238.   Result->BorderStyle = bsDialog;
  239.   Result->ClientWidth = DlgWidth;
  240.   Result->ClientHeight= DlgHeight;
  241.   Result->Position    = poScreenCenter;
  242.   Result->Name        = FormName;
  243.   Result->Caption     = FormName;
  244.   Font->Name          = "MS Sans Serif";
  245.   Font->Size          = 8;
  246.  
  247.   // ...create its pages (if a paged dialog box was selected).
  248.   if (Definition.Contains(daMultPg))
  249.   {
  250.     PgCtrl         = new TPageControl(Result);
  251.     PgCtrl->Parent = Result;
  252.     PgCtrl->Name   = "PageControl1";
  253.     PgCtrl->Align  = alClient;
  254.  
  255.     String s = PageNames->Lines[0].Text;
  256.     int i = 0;
  257.     int p;
  258.     while ((p = s.Pos((String)("\n"))) != NULL) {
  259.       TTabSheet *temp   = new TTabSheet(Result);
  260.       temp->Parent      = Result;
  261.       temp->PageControl = PgCtrl;
  262.       temp->Caption     = s.SubString(0, p-2);
  263.       ++i;
  264.       temp->Name        = Format("TabSheet%d",
  265.                                  OPENARRAY(TVarRec, (i)));
  266.       String ss = s.SubString(p+1, s.Length());
  267.       s = ss;
  268.     }
  269.   }
  270.  
  271.   // Setup and create vertical/horizontal buttons.
  272.   if (Definition.Contains(daBtnsH) || Definition.Contains(daBtnsV))
  273.   {
  274.  
  275.     // Get the starting point for the buttons and...
  276.     if (Definition.Contains(daBtnsH)) {
  277.       BtnPos = Point(Result->ClientWidth-((BtnWidth+2)*3)-(5*3),
  278.                      Result->ClientHeight-(BtnHeight+2)-5);
  279.     }
  280.     else
  281.       BtnPos = Point(Result->ClientWidth-(BtnWidth+2)-5,
  282.                      BtnHeight+5);
  283.  
  284.     // ...finalize positions.
  285.     if (Definition.Contains(daMultPg))
  286.     {
  287.       BtnPos.x -= 5;
  288.       if (Definition.Contains(daBtnsV))
  289.         BtnPos.y += 5;
  290.       else
  291.         BtnPos.y -= 5;
  292.     }
  293.  
  294.    // Create the buttons. This is the 'OK' button,...
  295.     TButton *temp     = new TButton(Result);
  296.     temp->Parent      = Result;
  297.     temp->Left        = BtnPos.x;
  298.     temp->Top         = BtnPos.y;
  299.     temp->Height      = BtnHeight;
  300.     temp->Width       = BtnWidth;
  301.     temp->Caption     = LoadStr(sOKButton);
  302.     temp->Name        = "Button1";
  303.     temp->Default     = True;
  304.     temp->ModalResult = mrOk;
  305.  
  306.     // (Move to the next button position)
  307.     if (Definition.Contains(daBtnsH))
  308.       BtnPos.x += BtnWidth + 5;
  309.     else
  310.       BtnPos.y += BtnHeight + 5;
  311.  
  312.     // ...this is the 'Cancel' button and...
  313.     temp              = new TButton(Result);
  314.     temp->Parent      = Result;
  315.     temp->Left        = BtnPos.x;
  316.     temp->Top         = BtnPos.y;
  317.     temp->Height      = BtnHeight;
  318.     temp->Width       = BtnWidth;
  319.     temp->Name        = "Button2";
  320.     temp->Caption     = LoadStr(sCancelButton);
  321.     temp->Cancel      = True;
  322.     temp->ModalResult = mrCancel;
  323.  
  324.     // (Move to the next button position)
  325.     if (Definition.Contains(daBtnsH))
  326.       BtnPos.x += 75 + 5;
  327.     else
  328.       BtnPos.y += 25 + 5;
  329.  
  330.     // ...this is the 'Help' button.
  331.     temp          = new TButton(Result);
  332.     temp->Parent  = Result;
  333.     temp->Left    = BtnPos.x;
  334.     temp->Top     = BtnPos.y;
  335.     temp->Height  = BtnHeight;
  336.     temp->Width   = BtnWidth;
  337.     temp->Name    = "Button3";
  338.     temp->Caption = LoadStr(sHelpButton);
  339.   }
  340.  
  341.   return Result;
  342. } // end of TDlgExpert::DoFormCreation()
  343.  
  344. //========================================= TDlgExpert ==========
  345. TMemoryStream* __fastcall TDlgExpert::CreateForm(const String FormIdent)
  346. {
  347.   TForm         *DlgForm;
  348.   TMemoryStream *Result;
  349.  
  350.   DlgForm = DoFormCreation(FormIdent);
  351.   try
  352.   {
  353.     Result = new TMemoryStream;
  354.     Result->WriteComponentRes(FormIdent, DlgForm);
  355.     Result->Position = 0;
  356.   } catch(...)
  357.   {
  358.     delete DlgForm;
  359.     delete Result;
  360.   }
  361.  
  362.   delete DlgForm;
  363.   return Result;
  364. } // end of TDlgExpert::CreateForm()
  365.  
  366. //========================================= TDlgExpert ==========
  367. TMemoryStream* __fastcall TDlgExpert::CreateHdrSource(const String UnitIdent,
  368.                                                       const String FormIdent)
  369. {
  370.   TMemoryStream *Result;
  371.  
  372.   SourceBuffer = new char[SourceBufferSize];
  373.   try
  374.   {
  375.     Result = new TMemoryStream;
  376.     try
  377.     {
  378.       // Write header's macro guard and includes:
  379.       //#ifndef tunameH
  380.       //#define tunameH
  381.       //
  382.       //#include <SysUtils.hpp>
  383.       //#include <Windows.hpp>
  384.       //#include <Messages.hpp>
  385.       //#include <Classes.hpp>
  386.       //#include <Graphics.hpp>
  387.       //#include <Controls.hpp>
  388.       //#include <StdCtrls.hpp>
  389.       //#include <ExtCtrls.hpp>
  390.       //#include <Forms.hpp>
  391.       {
  392.       String s = (String)SEPARATOR + CRLF;
  393.       s       += (String)"#ifndef %sH" + CRLF;
  394.       s       += (String)"#define %sH" + CRLF;
  395.       s       += (String)SEPARATOR + CRLF;
  396.       s       += (String)"#include <vcl\\SysUtils.hpp>" + CRLF;
  397.       s       += (String)"#include <vcl\\Windows.hpp>" + CRLF + CRLF;
  398.       s       += (String)"#include <vcl\\Messages.hpp>" + CRLF;
  399.       s       += (String)"#include <vcl\\Classes.hpp>" + CRLF;
  400.       s       += (String)"#include <vcl\\Graphics.hpp>" + CRLF;
  401.       s       += (String)"#include <vcl\\Controls.hpp>" + CRLF;
  402.       s       += (String)"#include <vcl\\StdCtrls.hpp>" + CRLF;
  403.       s       += (String)"#include <vcl\\ExtCtrls.hpp>" + CRLF;
  404.       s       += (String)"#include <vcl\\Forms.hpp>" + CRLF + CRLF;
  405.       FmtWrite(Result, s.c_str(),
  406.                OPENARRAY(TVarRec, (UnitIdent, UnitIdent)));
  407.       }
  408.  
  409.       // If multipage dialogbox, include COMCTLS.HPP
  410.       if (Definition.Contains(daMultPg)) {
  411.         String s  = (String)"#include <vcl\\ComCtrls.hpp>" + CRLF;
  412.                s += (String)CRLF + SEPARATOR + CRLF;
  413.         FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (NULL)));
  414.       }
  415.  
  416.       // The class declaration
  417.       {
  418.       String s  = (String)"class T%s: public TForm" + CRLF;
  419.                s += (String)"{" + CRLF;
  420.                s += (String)"__published:" + CRLF;
  421.       FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (FormName)));
  422.       }
  423.  
  424.       // Add variable declarations
  425.       if (Definition.Contains(daBtnsH) || Definition.Contains(daBtnsV))
  426.       {
  427.         String s  = (String)"%sTButton *Button1;" + CRLF;
  428.                s += (String)"%sTButton *Button2;" + CRLF;
  429.                s += (String)"%sTButton *Button3;" + CRLF;
  430.         FmtWrite(Result, s.c_str(),
  431.                  OPENARRAY(TVarRec, (INDENT, INDENT, INDENT)));
  432.        }
  433.  
  434.       // If this is a multipage dialogbox...
  435.       if (Definition.Contains(daMultPg))
  436.       {
  437.  
  438.         // ...we'll need a page control object and...
  439.         String s = (String)"%sTPageControl *PageControl1;" + CRLF;
  440.         FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (INDENT)));
  441.  
  442.         // ...tabsheet objects for each page.
  443.         if (PageNames->Lines->Count > 0)
  444.           for (int i = 0; i < PageNames->Lines->Count; i++) {
  445.             String s = (String)"%sTTabSheet *TabSheet%d;" + CRLF;
  446.             FmtWrite(Result, s.c_str(),
  447.                      OPENARRAY(TVarRec, (INDENT, i + 1)));
  448.           }
  449.       }
  450.  
  451.       // Write the user maintained class sections and the class's
  452.       // constructor prototype:
  453.       //private:
  454.       //public:
  455.       //    virtual __fastcall Tclassname(TComponent *Owner);
  456.       //};
  457.       {
  458.       String s  = (String)"private:" + CRLF;
  459.              s += (String)"public:" + CRLF;
  460.              s += (String)"%svirtual __fastcall T%s(TComponent *Owner);" + CRLF;
  461.              s += (String)"};" + CRLF;
  462.       FmtWrite(Result, s.c_str(),
  463.                OPENARRAY(TVarRec, (INDENT, FormName)));
  464.       }
  465.  
  466.       // Write the form's extern and close the macro guard:
  467.       //---------------------------------------------------------
  468.       //extern TClassname *classname;
  469.       //---------------------------------------------------------
  470.       //
  471.       //#endif // headernameH
  472.       {
  473.       String s  = (String)SEPARATOR + CRLF;
  474.              s += (String)"extern T%s *%s;" + CRLF;
  475.              s += (String)SEPARATOR + CRLF;
  476.              s += (String)"#endif"; // // %sH" + CRLF;
  477.       FmtWrite(Result, s.c_str(),
  478.                OPENARRAY(TVarRec, (FormName, FormName)));
  479.       }
  480.  
  481.       // Finally, rewind to start of stream.
  482.       Result->Position = 0;
  483.  
  484.     } catch(...)
  485.     {
  486.       delete Result;
  487.       Result = NULL;
  488.     }
  489.   } catch(...)
  490.   {
  491.     delete SourceBuffer;
  492.     SourceBuffer = NULL;
  493.   }
  494.  
  495.   delete SourceBuffer;
  496.   SourceBuffer = NULL;
  497.   return Result;
  498. } // end of TDlgExpert::CreateSource()
  499.  
  500. //========================================= TDlgExpert ==========
  501. TMemoryStream* __fastcall TDlgExpert::CreateSource(const String UnitIdent,
  502.                                                    const String FormIdent)
  503. {
  504.   TMemoryStream *Result;
  505.  
  506.   try
  507.   {
  508.     SourceBuffer = new char[SourceBufferSize];
  509.     Result = new TMemoryStream;
  510.     try
  511.     {
  512.       // CPP (source) setup looks like:
  513.       //---------------------------------------------------------
  514.       //#include <vcl.h>
  515.       //#pragma hdrstop
  516.       //
  517.       {
  518.       String s  = (String)SEPARATOR + CRLF;
  519.              s += (String)"#include <vcl.h>" + CRLF;
  520.              s += (String)"#pragma hdrstop" + CRLF;
  521.       FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (NULL)));
  522.       }
  523.  
  524.       // Additional include if multipaged dialog selected
  525.       //#include <ComCtrls.h>
  526.       if (Definition.Contains(daMultPg)) {
  527.         String s = (String)"#include <vcl\\ComCtrls.hpp>" + CRLF;
  528.         FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (NULL)));
  529.       }
  530.  
  531.       // Include the source's own header file:
  532.       //#include <modnam.h>
  533.       //---------------------------------------------------------
  534.       //#pragma resource "*.dfm"
  535.       //
  536.       {
  537.       sprintf(SourceBuffer, "\n\r#include \"%s.h\"\n\r\n\r"
  538.                             "#pragma resource \"*.dfm\"\n\r",
  539.               UnitIdent.c_str());
  540.       Result->Write(SourceBuffer, strlen(SourceBuffer));
  541.       }
  542.  
  543.       // Add variable declarations and constructor:
  544.       //TOKRightDlg *OKRightDlg;
  545.       //---------------------------------------------------------
  546.       //__fastcall TOKRightDlg::TOKRightDlg(TComponent *AOwner)
  547.       //                       :TForm(AOwner)
  548.       //{
  549.       //}
  550.       //---------------------------------------------------------
  551.       //
  552.       {
  553.       String s  = (String)"T%s *%s;" + CRLF + SEPARATOR + CRLF + CRLF;
  554.              s += (String)"__fastcall T%s::T%s(TComponent* AOwner)" + CRLF;
  555.              s += (String)"              :TForm(AOwner)" + CRLF;
  556.              s += (String)"{" + CRLF;
  557.              s += (String)"}" + CRLF +  SEPARATOR;
  558.       FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec,
  559.                                             (FormName, FormName,
  560.                                              FormName, FormName)));
  561.       }
  562.  
  563.       // Finally, rewind to start of stream.
  564.       Result->Position = 0;
  565.     } catch(...)
  566.     {
  567.       delete Result;
  568.       Result = NULL;
  569.     }
  570.   } catch(...)
  571.   {
  572.     delete SourceBuffer;
  573.     SourceBuffer = NULL;
  574.   }
  575.  
  576.   delete SourceBuffer;
  577.   SourceBuffer = NULL;
  578.   return Result;
  579. } // end of TDlgExpert::CreateSource()
  580.  
  581. //========================================= TDlgExpert ==========
  582. void __fastcall TDlgExpert::FmtWrite(TStream *Stream, char *Fmt,
  583.                                      const TVarRec *Args,
  584.                                      const int Args_Size)
  585. {
  586.   String p("%");
  587.   String f(Fmt);
  588.  
  589.   if (Stream && SourceBuffer)
  590.   {
  591.     StrLFmt(SourceBuffer, SourceBufferSize, Fmt, Args, Args_Size);
  592.     Stream->Write(SourceBuffer, strlen(SourceBuffer));
  593.   }
  594. } // end of TDlgExpert::FmtWrite()
  595.  
  596. //***************************************************************
  597. void __stdcall DialogExpert(TIToolServices *ToolServices)
  598. {
  599.   TDlgExpert     *D;
  600.   auto_ptr<TIMemoryStream> ISourceStream;
  601.   auto_ptr<TIMemoryStream> IFormStream;
  602.   auto_ptr<TIMemoryStream> IHdrStream;
  603.   auto_ptr<TFileName>      FileName;
  604.   String                   UnitIdent;
  605.   String                   FormIdent;
  606.  
  607.   // If we were not pass a toolservices object, forget it.
  608.   if (!ToolServices) exit(1);
  609.  
  610.   try {
  611.     FileName.reset(new TFileName);
  612.  
  613.     // If we can get a name set for the new dialog box...
  614.     if (ToolServices->GetNewModuleName(UnitIdent, *FileName)) {
  615.       try
  616.       {
  617.         // ...allocate the dialog expert and set the path for the
  618.         // dialog box files.
  619.         D = new TDlgExpert(Application);
  620.  
  621.         // Display the dialog expert dialog box modally. If we
  622.         // come back with a go...
  623.         if (D->ShowModal() == mrOK) {
  624.  
  625.           // ...make everything but the first letter of the unit
  626.           // name lowercase.
  627.           UnitIdent.LowerCase();
  628.           UnitIdent[0] &= 0x5F ;
  629.  
  630.           // The form's file name is dependent on the button
  631.           // orientation and we add a number to the end to reduce
  632.           // name conflict when several dialogs are created in
  633.           // quick succession.
  634.           FormIdent = "Form" + UnitIdent.SubString(5, 255);
  635.  
  636.           // Get a stream for the form (name.DFM),...
  637.           try
  638.           {
  639.             IFormStream.reset(new TIMemoryStream(D->CreateForm(FormIdent)));
  640.             IFormStream.get()->AddRef();
  641.             try
  642.             {
  643.               // ...the source file (name.CPP) and...
  644.               ISourceStream.reset(new TIMemoryStream(D->CreateSource(UnitIdent,
  645.                                                                      FormIdent)));
  646.               ISourceStream.get()->AddRef();
  647.               try {
  648.  
  649.                 // ...the header file (name.H).
  650.                 IHdrStream.reset(new TIMemoryStream(D->CreateHdrSource(UnitIdent,
  651.                                                                        FormIdent)));
  652.                 IHdrStream.get()->AddRef();
  653.  
  654.                 // Setup the create flags and...
  655.                 TCreateModuleFlags CreateFlags;
  656.                 CreateFlags << cmAddToProject << cmShowSource
  657.                             << cmShowForm << cmUnNamed
  658.                             << cmMarkModified;
  659.  
  660.                 // ...create the dialog box source set.
  661.                 ToolServices->CreateCppModule(*FileName, "", "", "",
  662.                                               IHdrStream.get(),
  663.                                               ISourceStream.get(),
  664.                                               IFormStream.get(),
  665.                                               CreateFlags);
  666.               } catch(...)
  667.               {
  668.                 ISourceStream.get()->OwnStream = true;
  669.                 IFormStream.get()->OwnStream = true;
  670.               }
  671.             } catch(...)
  672.             {
  673.               IFormStream.get()->OwnStream = true;
  674.             }
  675.           } catch(...)
  676.           {
  677.           }
  678.  
  679.         }
  680.       } catch(...)
  681.       {
  682.         delete D;
  683.       }
  684.     }
  685.   } catch(...)
  686.   {
  687.   }
  688.  
  689.   if (ISourceStream.get()) ISourceStream.get()->OwnStream = true;
  690.   if (IFormStream.get()) IFormStream.get()->OwnStream = true;
  691.   if (IHdrStream.get()) IHdrStream.get()->OwnStream = true;
  692.   delete D;
  693. } // end of DialogExpert()
  694.  
  695. //---------------------------------------------------------------
  696.  
  697.